/* eslint-disable no-unused-vars */
import { reqlogin } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'

export default {
  namespaced: true,
  state: {
    token: getToken()
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    }
  },
  actions: {
    // async login(context, form) {
    //   const { data } = await reqlogin(form)
    //   const token = data.data
    //   setToken(token)
    //   context.commit('setToken', token)
    //   return data
    // }
    login(context, data) {
      return new Promise((resolve, reject) => {
        reqlogin(data).then(res => {
          const token = res.data.data
          setToken(token)
          context.commit('setToken', token)
          resolve(res)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
  // getters: {}
}
